package com.x.chalk.service.impl;
////////////////////////////////////////////////////////////////////
//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.___\_____/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//            佛祖保佑       永不宕机     永无BUG                   //
////////////////////////////////////////////////////////////////////

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.x.chalk.dao.AddressDao;
import com.x.chalk.dao.CourseDao;
import com.x.chalk.dao.OrderDao;
import com.x.chalk.entity.Address;
import com.x.chalk.entity.Course;
import com.x.chalk.service.intf.OrderService;
import com.x.chalk.vo.R;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wsc
 * @create 2022-10-04 20:11
 */
@Service
public class OrderServiceImpl implements OrderService {

    private final OrderDao dao;
    private final CourseDao courseDao;
    private final AddressDao addressDao;

    public OrderServiceImpl(OrderDao dao, CourseDao courseDao, AddressDao addressDao) {
        this.dao = dao;
        this.courseDao = courseDao;
        this.addressDao = addressDao;
    }

    @Override
    public R queryPre(long id, String token) {
        if (id > 0) {
            long uid = Long.parseLong(token);
            //获取收货地址信息
            QueryWrapper<Address> wrapper = new QueryWrapper<>();
            wrapper.eq("uid", uid);
            wrapper.eq("state", 1);
            Address address = addressDao.selectOne(wrapper);

            Course course = courseDao.selectCourse(id);

            Map<String, Object> map1 = new HashMap<>();
            map1.put("id", address.getId());
            map1.put("receive", address.getName() + "    " + address.getPhone());
            map1.put("detail", address.getProvince() + address.getCity() + address.getArea() + address.getDetail());

            Map<String, Object> map2 = new HashMap<>();
            map2.put("address", map1);
            map2.put("course", course);

            return R.ok(map2);
        }
        return R.fail();
    }

    @Override
    public R createOrder() {
        return null;
    }
}
